package com.jtpay.ysfproductionprocess.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.jtpay.ysfproductionprocess.http.ApiHelper;

import static com.jtpay.ysfproductionprocess.utils.PayContext.PAYMENT;

public final class LogUtil {
    private static ApiHelper apiHelper;
    private static SharedPreferenceUtil sharedPreferenceUtil = new SharedPreferenceUtil();

    public static void log(String content) {
        Log.d(PayContext.TAG, content);
        PayFileUtil.saveLogFile(content);
    }

    public static void logOnlySave(String content) {
        PayFileUtil.saveLogFile(content);
    }

    /**
     * @param logContent 日志内容
     * @param module     日志模块（抓单，通知，打点)
     * @param levelEnum  错误的类型
     */

    @SuppressLint("ShowToast")
    public static void logUpload(Context context, String logContent, String module, String levelEnum) {
        String ysfAccount = sharedPreferenceUtil.SP_READ(context,
                        PayContext.SP_SHOP_YSF_ACCOUNT_KEY);
        if (TextUtils.isEmpty(ysfAccount)){
            return;
        }
        if (apiHelper == null) {
            apiHelper = ApiHelper.getInstance(context);
        }
        apiHelper.singleLogUploadAPI(ysfAccount, module, levelEnum, logContent, PAYMENT);
    }
}
